package com.kh.statistics.video.utils;

import org.apache.commons.lang.StringUtils;

import java.util.Map;

/**
 * @BelongsProject: statistics
 * @BelongsPackage: com.kh.statistics.video.utils
 * @Author: Hong.Kong
 * @CreateTime: 2024-06-14  17:30
 * @Description: TODO
 * @Version: 1.0
 */
public class ParamsUtils {

    public static String withParams(Map<String, String> params) {
        StringBuilder builder = new StringBuilder();

        params.forEach((k, v) -> {
            builder.append(k + "=" + v + "&");
        });
        String all = builder.toString();
        return StringUtils.substringBeforeLast(all, "&");
    }


    public static String parseCookiesAndGet(String cookies, String key) {
        String[] split = cookies.split(";");
        for (String s : split) {
            String[] split1 = s.split("=");
            if (split1[0].trim().equals(key)) {
                return split1[1];
            }
        }
        return null;
    }

}
